<style>
div.gridbox_xp table.obj td {
	border-bottom:thin dashed;
	border-right:none;
}
</style>
<div id="adminServicesToolbarContainer"></div>
<div id="adminServicesGridContainer" style="width:100%;height:450px;"></div>

<script>

function adminServicesAjaxRequest(url,content) {
	dojo.xhrPost ({
		url: url,
		handleAs: "json",
		content: content,
		load: function (data) {
			adminServicesGridReload();
		},
		error: function (error) {
			console.error ('Error: ', error);
		}
	});
}

function adminServicesMenuSettings(val) {
	adminServicesAjaxRequest("<?=$this->baseUrl?>/menu-manager.raw/ajax-change-cache-settings",{cacheMode:val});
}

function adminServicesNSDRSystem(event) {
	adminServicesAjaxRequest("<?=$this->baseUrl?>/nsdr.raw/system",{event:event});
}

function adminServicesToolbarOnLoaded() {
	adminServicesToolbar.forEachItem(function (id) {
			adminServicesToolbar.hideItem(id);
		});
}

var adminServicesToolbar = new dhtmlXToolbarObject("adminServicesToolbarContainer","ClearSilver");
adminServicesToolbar.loadXML("<?=$this->baseUrl?>/admin-services.raw/toolbar",adminServicesToolbarOnLoaded);
adminServicesToolbar.setIconsPath("<?=$this->baseUrl?>/img/");
function adminServicesToolbarOnClicked(id) {
	switch(id) {
		case "tbStart":
			adminServicesNSDRSystem('start');
			break;
		case "tbStop":
			adminServicesNSDRSystem('unload');
			break;
		case "tbRestart":
			adminServicesNSDRSystem('reload');
			break;
		case "tbClear":
			adminServicesMenuSettings('clear');
			break;
		case "tbEnable":
			adminServicesMenuSettings('enable');
			break;
		case "tbDisable":
			adminServicesMenuSettings('disable');
			break;
		default:
			alert('<?=__("Invalid event: ")?>'+id);
	}
}
adminServicesToolbar.attachEvent("onClick",adminServicesToolbarOnClicked);

var adminServicesGrid =  new dhtmlXGridObject("adminServicesGridContainer");
adminServicesGrid.setImagePath("<?=$this->baseUrl?>/img/");
adminServicesGrid.setHeader('<?=__('Services')?>,<?=__('Status')?>');
adminServicesGrid.setColTypes("ro,ro");
adminServicesGrid.setSkin("xp");
adminServicesGrid.setInitWidths("*");
adminServicesGrid.enableDragAndDrop(true);
adminServicesGrid.init();
function adminServicesGridReload() {
	adminServicesToolbarOnLoaded();
	adminServicesGrid.clearAll();
	adminServicesGrid.load('<?=$this->baseUrl?>/admin-services.raw/list-services',null,"json");
}
adminServicesGridReload();

function adminServicesOnRowSelected(rowId,cellIndex) {
	adminServicesToolbarOnLoaded();
	switch (rowId) {
		case "nsdr":
			adminServicesToolbar.showItem("tbStart");
			adminServicesToolbar.showItem("tbStop");
			adminServicesToolbar.showItem("tbRestart");
			break;
		case "menu":
			adminServicesToolbar.showItem("tbClear");
			adminServicesToolbar.showItem("tbEnable");
			adminServicesToolbar.showItem("tbDisable");
			break;
	}
}
adminServicesGrid.attachEvent("onRowSelect",adminServicesOnRowSelected);

</script>
